<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8"/>
    <title>update-employee</title>
    <script type="text/javascript" th:src="@{/layui/layui.js}"></script>
    <script type="text/javascript" th:src="@{/jquery/jquery-1.8.3.js}"></script>
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}"/>
    <script type="text/javascript">
        layui.use('form', function () {
            var form = layui.form;

            //监听提交
            form.on('submit(formDemo)', function (data) {

                // layer.msg(JSON.stringify(data.field));
                $.ajax({
                    url: '/employee/updateEmpolyee',
                    type: 'PUT',
                    data: {
                        id: data.field.id,
                        name: data.field.name,
                        department: data.field.department
                    },
                    success: function (data) {
                        if (data.success) {
                            layer.open({
                                title: '信息',
                                content: data.message,
                                yes: function (index, layero) {
                                    //do something
                                    layer.close(index); //如果设定了yes回调，需进行手工关闭
                                    location.href = '/templates/employee/list';
                                }
                            });

                        }
                    },
                    error: function (error) {

                    }

                });
                return false;


            });
        });
    </script>
    <style type="text/css">
        .form {
            width: 500px;
        }
    </style>
</head>
<body>
<div class="body">
    <div class="form">
        <div class="layui-form">
            <input type="hidden" name="id" th:value="${employee.id}">
            <div class="layui-form-item">
                <label class="layui-form-label">姓名：</label>
                <div class="layui-input-block">
                    <input type="text" name="name" class="layui-input" th:value="${employee.name}"
                           lay-verify="required" placeholder="请输入姓名" autocomplete="off"/>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">部门：</label>
                <div class="layui-input-block">
                    <select name="department" lay-verify="required">
                        <option value="">请选择一个部门</option>
                        <option value="1">信息部</option>
                        <option value="2">技术部</option>
                        <option value="3">人事部</option>
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="formDemo">修改</button>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
</html>